<template>
  <div>
    <upload-excel :before-upload="beforeUpload" :on-success="onSuccess" />
  </div>
</template>

<script>
import { importEmployee } from '@/api/employees'
import { getImportData } from '@/utils/excelData'
export default {
  methods: {
    beforeUpload(file) {
      const isLt1M = file.size / 1024 / 1024 < 1

      if (isLt1M) {
        return true
      }

      this.$message({
        message: 'Please do not upload files larger than 1m in size.',
        type: 'warning'
      })
      return false
    },
    async onSuccess({ results, header }) {
      await importEmployee(getImportData(results))
      this.$router.back()
      this.$message.success('导入成功')
    }
  }

}
</script>

<style>

</style>
